package com.xpqh.ksg.modular.periphery.controller;

import com.xpqh.ksg.base.BaseController;
import com.xpqh.ksg.base.BaseResponseDTO;
import com.xpqh.ksg.modular.periphery.dto.KsgProductPeripheryDetailsReqDTO;
import com.xpqh.ksg.modular.periphery.dto.KsgPeripheryListReqDTO;
import com.xpqh.ksg.modular.periphery.service.PeripheryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/ksg/periphery")
public class PeripheryController extends BaseController {

    @Autowired
    private PeripheryService peripheryService;

    @PostMapping("/list")
    public BaseResponseDTO list(@Valid @RequestBody KsgPeripheryListReqDTO req) {
        return renderResultOk(peripheryService.getProductPeripheryList(req.getSearchContent(),req.getOrder(), req.getLabel(), req.getPageNo(),req.getPageSize()));
    }
    @PostMapping("/details")
    public BaseResponseDTO details(@Valid @RequestBody KsgProductPeripheryDetailsReqDTO req) {
        return renderResultOk(peripheryService.getProductPeripheryDetails(req.getAutoId()));
    }

    @PostMapping("/like/save")
    public BaseResponseDTO doLike(@Valid @RequestBody KsgProductPeripheryDetailsReqDTO req) {
        peripheryService.doLike(req.getAutoId());
        return renderResultOk();
    }
}

